#include <ucontext.h>
#include <stdio.h>
#include <stdlib.h>

//Representa a thread
typedef struct thread
{
	int tid;
	int idBloqueante;
	ucontext_t contexto;
	struct thread *prox;
} thread;

//Representa a fila Ready e Blocked
typedef struct Fila
{
	thread *ini;
	thread *fim;
} Fila;

typedef struct umutex_t
{
	int busy;


} umutex_t;

void inserir_fila ( thread *novo, Fila *umaFila );

thread* pegarPrimeiroFila(Fila *umaFila);

thread* acharthread(int id, thread* umaFila);

int existeNaFila(int id, Fila fila);


int Identificadores[256];

//Filas
Fila ready, blocked;

//Thread que está atualmente em execução
thread *running;

//Contexto do escalonador
ucontext_t schedulerContext;

ucontext_t mainThread;

//Controla qual thread irá ser executada
void escalonador( void );

//Função de Inicialização
int libuthread_init( void );

//Para criar as threads
int uthread_create( void (*start_routine)(), void *arg );

//Yield
void uthread_yield( void );

//Join
int uthread_join( int thr );

int uthread_lock(umutex_t lock[]);

int uthread_unlock (umutex_t lock[]);
